﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Management
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        private string connectionString = "Data Source=D:\\Project\\VC\\Net\\Management\\STUManagement.db;Version=3;";
        private string loginQuery = "SELECT Username, Password FROM User WHERE Username = @Username;";

     

        private void LoginSystem()
        {
            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(loginQuery, connection))
                {
                    command.Parameters.AddWithValue("@Username", textBox1.Text);

                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string username = reader["Username"].ToString();
                            string password = reader["Password"].ToString();

                            if (textBox1.Text == username && textBox2.Text == password)
                            {
                                // Login successful
                                new Information().Show();
                                this.Hide();
                                return;
                            }
                        }
                    }
                }
            }

            MessageBox.Show("登录失败！", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoginSystem();

        }

     
    }
}
